package com.cx.bank.config;

import org.aopalliance.intercept.Joinpoint;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    //拦截器
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //登陆成功之后应该有用户的session
        Object loginUser = request.getSession().getAttribute("currentUser");
        if(loginUser==null){//没有登陆
            request.setAttribute("msg","用户无权限，请先登录！");
//            request.getRequestDispatcher("/loginPage").forward(request,response);

            response.sendRedirect("/loginPage");
            return false;
        }else {
            return true;
        }

    }

}